package com.mew.game.core.common.handler;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @Author King.Song
 * @Date 2020/11/21 0021
 **/
public class RoomInfoManager {

    private static RoomInfoManager roomInfoManager = new RoomInfoManager();
    private final ConcurrentMap<Integer, RoomBO> roomCache = new ConcurrentHashMap<>(16);
    private RoomInfoManager(){}

    public static RoomInfoManager getInstance() {
        if (roomInfoManager == null) {
            synchronized (RoomInfoManager.class) {
                if (roomInfoManager == null) {
                    roomInfoManager = new RoomInfoManager();
                }
            }
        }
        return roomInfoManager;
    }


    public void put(RoomBO room){
        roomCache.put(room.getRoomId(), room);
    }

    public void remove(int roomId){
        roomCache.remove(roomId);
    }

    public RoomBO get(int roomId){
        return roomCache.get(roomId);
    }

    public void updateBetStr(RoomBO roomBO, String betStr){
        if (!betStr.equals(roomBO.getBetStr())){
            roomBO.setBetStr(betStr);
        }
    }


}
